package com.heima.sh.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.heima.service.CheckItemService;
import com.heima.sh.constant.MessageConstant;
import com.heima.sh.entity.PageResult;
import com.heima.sh.entity.QueryPageBean;
import com.heima.sh.mapper.CheckItemMapper;
import com.heima.sh.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/***
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

@Service(interfaceClass = CheckItemService.class)
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    @Override
    public void addCheckItem(CheckItem checkItem) {
        checkItemMapper.addCheckItem(checkItem);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());

        List<CheckItem> checkItemList = checkItemMapper.findCheckItemByCondition(queryPageBean.getQueryString());

        PageInfo<CheckItem> checkItemPageInfo = new PageInfo<>(checkItemList);

        PageResult pageResult = new PageResult(checkItemPageInfo.getTotal(), checkItemPageInfo.getList());
        return pageResult;

    }


    @Override
    public void deleteCheckItemById(Integer id) {

        Integer count = checkItemMapper.findCheckgroupCheckitemByCheckItemId(id);

        if(count >0){
            throw new RuntimeException("该检查项目一被应用，无法删除！");
        }

        checkItemMapper.deleteCheckItemById(id);
    }

}

/***
 *                    .::::.
 *                  .::::::::.
 *                 ::::::::::: 
 *             ..:::::::::::'
 *           '::::::::::::'
 *             .::::::::::
 *        '::::::::::::::..
 *             ..::::::::::::.
 *           ``::::::::::::::::
 *            ::::``:::::::::'        .:::.
 *           ::::'   ':::::'       .::::::::.
 *         .::::'      ::::     .:::::::'::::.
 *        .:::'       :::::  .:::::::::' ':::::.
 *       .::'        :::::.:::::::::'      ':::::.
 *      .::'         ::::::::::::::'         ``::::.
 *  ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 *                    '.:::::'                    ':'````..
 */